package com.swak.frame.support;

import java.util.ServiceLoader;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.core.annotation.Order;
import com.google.common.collect.Lists;
import com.swak.frame.SwakConstants;
import com.swak.frame.filter.ApiFilter;

@Configuration(proxyBeanMethods = false)
@Order(SwakConstants.ORDER_PRECEDENCE)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class DefaultServiceConfigurer implements SwakServiceConfigurer {

    @Override
    public void configureFilterHandler(ConfigPipeline<ApiFilter> filterPipeline) {
        ServiceLoader<ApiFilter> serviceLoader = ServiceLoader.load(ApiFilter.class);
        filterPipeline.addLast(Lists.newArrayList(serviceLoader.iterator()));
    }
}
